package org.wdj.jpa.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.wdj.jpa.entity.SysUser;

//JpaRepository<SysUser, Long> ,第一个参数指定 Entity 实体类，第二个指定主键类型
@Repository
public interface SysUserRepository extends JpaRepository<SysUser, Long> {

    //根据用户名查询用户信息
    SysUser findByUsername(String username);

    //自定义查询 sql
    @Query("select sysUser from SysUser sysUser where sysUser.nickname like %:nickname%")
    Page<SysUser> searchByNickname(@Param("nickname") String nickname, Pageable pageable);

    Page<SysUser> findByNicknameLike(@Param("nickname") String nickname, Pageable pageable);
}
